package com.zzyl.serve.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.domain.Elder;
import com.zzyl.serve.dto.BindingElderDto;
import com.zzyl.serve.dto.DeviceDataDto;
import com.zzyl.serve.dto.DeviceDataPageReqDto;
import com.zzyl.serve.dto.UserLoginRequestDto;
import com.zzyl.serve.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.FamilyMember;
import com.zzyl.serve.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author itheima
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;




    /**
     * 小程序端 用户登录
     */
	@PostMapping("/login")
    @ApiOperation("小程序端 用户登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto dto) {

        LoginVo vo = familyMemberService.login(dto);


        return R.ok(vo);
    }



    /**
     * 绑定老人
     * @param dto
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult bindFamilyMember(@RequestBody BindingElderDto dto) {
        familyMemberService.bindFamilyMember(dto);
        return success("绑定成功");
    }


    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult queryFamilyMemberElderList() {

        return success(familyMemberService.queryFamilyMemberElderList());
    }


    /**
     * 分页查询家人列表
     */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public AjaxResult pageFamilyMemberElder() {
        startPage();
        return success(familyMemberService.pageFamilyMemberElder());
    }


    /**
     * 查询老人健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("分页查询家人列表")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId) {

        return success(familyMemberService.queryServiceProperties(iotId));
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(DeviceDataDto dto) {

        return success(familyMemberService.queryDeviceDataListByDay(dto));
    }


    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(DeviceDataDto dto) {

        return success(familyMemberService.queryDeviceDataListByWeek(dto));
    }
}
